import { Column, Entity, ManyToMany, ManyToOne } from 'typeorm'
import { Menu } from './menu.entity'
import { Operate } from './operate.entity'
import { Role } from './role.entity'

@Entity()
export class Permission extends Operate {
  @Column({ name: 'permission_desc', type: 'varchar', length: 50, comment: '权限描述' })
  permissionDesc: string

  @Column({
    name: 'permission_code',
    type: 'varchar',
    length: 50,
    unique: true,
    comment: '权限代码',
  })
  permissionCode: string

  @ManyToMany(() => Role, (role) => role.permissions, {
    cascade: true,
  })
  roles: Role[]

  @ManyToOne(() => Menu, (menu) => menu.permissions, {
    cascade: true,
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  menu: Menu
}
